/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package networkrespnse;

import core.ParameterDecoder;
import utils.Utils;
/**
 *
 * @author Kvest
 */
public class PPCSettingsResponse extends Response
{
    private int T1,T2,T3;
    private int maxSendCoordsTime;
    private String javaVersion;
    private String link;
    private int maxOrdersCount;
    private int autoTariffClassUID;
    private boolean checkNoSubOrderForClose;
    
    public PPCSettingsResponse(byte[] data)
    {
        super(PPCSETTINGS_RESPONSE);
        T1 = 60000;
        T2 = 60000;
        T3 = 60000;
        maxSendCoordsTime = 60000;
        javaVersion = null;
        link = null;
        maxOrdersCount = -1;
        autoTariffClassUID = 0;
        checkNoSubOrderForClose = true;

        parse(data);
    }

    protected void parse(byte[] data)
    {
        byte[] body,temp;
        int index;

        //Получаем  body
        body = ParameterDecoder.getTransferBody(data);
        //Устанавливаем смещение
        temp = new byte[4];
        index = 0;
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        index += Utils.byteToInt(temp)+4;
        //MaxSendCoordsTime
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        maxSendCoordsTime = Utils.byteToInt(temp);
        index += 8;
        //T1
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        T1 = Utils.byteToInt(temp);
        //T2
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        T2 = Utils.byteToInt(temp);
        //T3
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        T3 = Utils.byteToInt(temp);

        try
        {
            //AutoTariffClassUID
            for (int i=0;i<4;i++)
            {
                    temp[i] = body[index++];
            }
            autoTariffClassUID = Utils.byteToInt(temp);

            //JavaVersion
            for (int i=0;i<4;i++)
            {
                    temp[i] = body[index++];
            }
            int size = Utils.byteToInt(temp);
            temp = new byte[size];
            for (int i=0;i<size;i++)
            {
                    temp[i] = body[index++];
            }
            javaVersion = Utils.byteToString(temp);
            // Линк на новую версию Java
            temp = new byte[4];
            for (int i=0;i<4;i++)
            {
                    temp[i] = body[index++];
            }
            size = Utils.byteToInt(temp);
            temp = new byte[size];
            for (int i=0;i<size;i++)
            {
                    temp[i] = body[index++];
            }
            link = Utils.byteToString(temp);
            //Кол-во одновременно взятых заказов
            temp = new byte[4];
            for (int i=0;i<4;i++)
            {
                    temp[i] = body[index++];
            }
            maxOrdersCount = Utils.byteToInt(temp);
        }catch(Exception e){}
    }

    public int getT1()
    {
        return T1;
    }

    public int getT2()
    {
        return T2;
    }

    public int getT3()
    {
        return T3;
    }

    public int getMaxSendCoordsTime()
    {
        return maxSendCoordsTime;
    }

    public String getJavaVersion()
    {
        return javaVersion;
    }

    public String getLink()
    {
        return link;
    }

    public int getMaxOrdersCount()
    {
        return maxOrdersCount;
    }

    public int getAutoTariffClassUID() 
    {
        return autoTariffClassUID;
    }

    public boolean isCheckNoSubOrderForClose() {
        return checkNoSubOrderForClose;
    }
}
